const Response = require('../utils/response');
const notificationService = require('../services/notificationService');

class NotificationController {
  // 获取通知列表
  async getNotifications(req, res) {
    try {
      const notifications = await notificationService.getNotifications(req.user.id);
      res.json(Response.success(notifications));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 获取通知详情
  async getNotificationById(req, res) {
    try {
      const notification = await notificationService.getNotificationById(req.params.id, req.user.id);
      res.json(Response.success(notification));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 标记单个通知为已读
  async markAsRead(req, res) {
    try {
      await notificationService.markAsRead(req.params.id);
      res.json(Response.success(null, '标记成功'));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 标记所有为已读
  async markAllAsRead(req, res) {
    try {
      await notificationService.markAllAsRead(req.user.id);
      res.json(Response.success(null, '标记成功'));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 删除所有通知
  async deleteAllNotifications(req, res) {
    try {
      await notificationService.deleteAllNotifications(req.user.id);
      res.json(Response.success(null, '清空成功'));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 创建通知
  async createNotification(req, res) {
    try {
      const result = await notificationService.createNotification(req.body);
      res.json(Response.success(result, '创建成功'));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }
}

module.exports = new NotificationController(); 